const fs = require('fs');
const { Transform } = require('stream');

exports.default = () => {
    // 文件读取流
    const read = fs.createReadStream('style.css');
    // 文件写入流
    const write = fs.createWriteStream('style.min.css');

    const transform = new Transform({
        transform:(chunk, encoding, callback) => {
            // chunk ---读取文件流中的内容（buffer）
            const input = chunk.toString();
            const output = input.replace(/\s+/g, '').replace(/\/\*.+?\*\//g, '');
            callback(null, output)
        }
    })
    // 把读出来的文件写入文件流
    read
    .pipe(transform)
    .pipe(write);
    return read;
}